import http from "@/utils/http";
import API from "../config/index";
export let getIp = async () => {
  let res = await fetch('https://ipv4.icanhazip.com/json');
  return res.text();
};


export let getIpInfo = () => {
  return http({
    url: `http://ip-api.com/json/?lang=zh-CN`,
    method: "get",
    withCredentials: false, // 添加这一行
    headers: {
      Origin:false,
      Referer: false,
    },
  });
};

export let getIpInfoBaidu = (ip) => {
  return http({
    url: `https://opendata.baidu.com/api.php?query=${ip}&co=&resource_id=6006&oe=utf8`,
    method: "get",
    withCredentials: false, // 添加这一行
    headers: {
      Origin:false,
      Referer: false,
    },
  });
};


export let getProxyIP = async () => {
 try {
  let ip = await getIp();
  return http({
    url: `${API.BASE_API}/proxy/v1/ip?ip=${ip}`,
    method: "get",
  });
 } catch (error) {
  console.log(error)
 }
};
